<template>
  <div class="main">
    <view class="content">
      <div class="msg_list">
        <view v-for="item in sysList" :key="index">
          <view class="type_sys" @click="toSysDetail(item)">
            <view class="icon_dot" v-show="!item.is_read"></view>
            <text class="title">{{item.title}}</text>
            <text class="time">{{item.time}}</text>
            <text class="desc">{{item.content}}</text>
          </view>
        </view>
        <!-- <view class="md-movie-list__tips">
          <view class="loadMore" @click="loadMoreFuc" v-if="!loadMore">加载更多</view>
          <view v-if="loadMore">
            <image class="md-movie-list__tips-image"  src="http://fanglilai-pic.oss-cn-shenzhen.aliyuncs.com/mw690/20180530/2018053010401974197.jpg" mode="aspectFill"/>
            <text class="md-movie-list__tips-text">正在加载...</text>
          </view>
          <view v-else>
            <text class="noMore" v-if="noMore">--------------- 我也是有底线的 -------------</text>
          </view>
       </view> -->
      </div>
    </view>
  </div>
</template>

<script>
import api from '@/utils/api'
export default {
  data () {
    return {
      showTopPopup: false,
      sysList: [],
      loadMore: false,
      noMore: false
    }
  },
  onShow () {
    this.opnoticelist(0, 0)
  },
  methods: {
    toSysDetail (item) {
      this.$router.push({ path: '/pages/message/sys_detail/main', query: { noticeId: item.notice_id } })
    },
    loadMoreFuc () {
      this.loadMore = !this.loadMore
      console.log('fdsfds')
      wx.showNavigationBarLoading()
        // wx.hideNavigationBarLoading() //完成停止加载
        // wx.stopPullDownRefresh() //停止下拉刷新
      console.log(this.loadMore)
    },
    formatTime (timestamps) {
      var date = new Date(timestamps * 1000)
      var curDate = new Date()
      var preDate = new Date(curDate.getTime() - 24 * 60 * 60 * 1000)
      var beforeDate = new Date(curDate.getTime() - 2 * 24 * 60 * 60 * 1000)
      var formatDate = ''
      if (date.getFullYear() === curDate.getFullYear() && date.getMonth() === curDate.getMonth() && date.getDate() === curDate.getDate()) {
        formatDate = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
      } else if (date.getFullYear() === preDate.getFullYear() && date.getMonth() === preDate.getMonth() && date.getDate() === preDate.getDate()) {
        formatDate = '昨天'
      } else if (date.getFullYear() === beforeDate.getFullYear() && date.getMonth() === beforeDate.getMonth() && date.getDate() === beforeDate.getDate()) {
        formatDate = '前天'
      } else {
        formatDate = ((date.getMonth() + 1) < 10 ? ('0' + (date.getMonth() + 1)) : (date.getMonth() + 1)) + '月' + (date.getDate() < 10 ? ('0' + date.getDate()) : date.getDate()) + '日'
      }
      return formatDate
    },
    opnoticelist (isLandlord, isSender) {
      var param = {}
      param['is_landlord'] = isLandlord
      param['is_sender'] = isSender
      const opnoticelist = api.opnoticelist(param)
      opnoticelist.then(d => {
        if (d.code === 200) {
          this.sysList = d.data.list
          for (var i = 0; i < this.sysList.length; i++) {
            this.sysList[i]['time'] = this.formatTime(this.sysList[i].create_time)
            console.log(Math.round((new Date().getTime() - 24 * 60 * 60 * 1000) / 1000).toString())
          }
        }
      })
      .catch((e) => {
        console.log(e)
      })
    }
  }
}
</script>

<style>
@import './index.css';
</style>
